package com.ruoyi.web.controller.system;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.DecimalFormat;
import java.util.*;

import com.ruoyi.system.mapper.ResiDataMapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ResiData;
import com.ruoyi.system.service.IResiDataService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 遥感数据管理Controller
 * 
 * @author ruoyi
 * @date 2024-03-20
 */
@Controller
@RequestMapping("/system/data")
@ResponseBody
public class ResiDataController extends BaseController {
    private String prefix = "system/data";

    @Autowired
    private IResiDataService resiDataService;


    @RequiresPermissions("system:data:view")
    @GetMapping()
    public String data() {
        return prefix + "/data";
    }

    /**
     * 查询遥感数据管理列表
     */
    @RequiresPermissions("system:data:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ResiData resiData) {
        startPage();
        List<ResiData> list = resiDataService.selectResiDataList(resiData);
        return getDataTable(list);
    }

    /**
     * 导出遥感数据管理列表
     */
    @RequiresPermissions("system:data:export")
    @Log(title = "遥感数据管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ResiData resiData) {
        List<ResiData> list = resiDataService.selectResiDataList(resiData);
        ExcelUtil<ResiData> util = new ExcelUtil<ResiData>(ResiData.class);
        return util.exportExcel(list, "遥感数据管理数据");
    }

    /**
     * 新增遥感数据管理
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存遥感数据管理
     */
    @RequiresPermissions("system:data:add")
    @Log(title = "遥感数据管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ResiData resiData) {
        return toAjax(resiDataService.insertResiData(resiData));
    }

    /**
     * 修改遥感数据管理
     */
    @RequiresPermissions("system:data:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        ResiData resiData = resiDataService.selectResiDataById(id);
        mmap.put("resiData", resiData);
        return prefix + "/edit";
    }

    /**
     * 修改保存遥感数据管理
     */
    @RequiresPermissions("system:data:edit")
    @Log(title = "遥感数据管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ResiData resiData) {
        return toAjax(resiDataService.updateResiData(resiData));
    }

    /**
     * 删除遥感数据管理
     */
    @RequiresPermissions("system:data:remove")
    @Log(title = "遥感数据管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(resiDataService.deleteResiDataByIds(ids));
    }

    /**
     * 面积统计
     *
     * @param date
     * @return
     */
    @PostMapping("/area")
    public ArrayList area(Date date) {
        ArrayList arrayList = resiDataService.areaService(new Date());
        return arrayList;
    }

    private ResiDataMapper resiDataMapper;

    public ResiDataController(ResiDataMapper resiDataMapper) {
        this.resiDataMapper = resiDataMapper;
    }

    @RequestMapping("/get1")
    @ResponseBody
    public String []  getYearlyAverages() {
        String [] data = resiDataService.getYearlyAverages();
        return data;
    }
}
